//
//  UINavigationControler++.swift
//  iOS_Com_Extensions
//
//  Created by 家和20240415 on 2024/12/16.
//

import UIKit

extension UINavigationController {
    func pushOrPop(vc: UIViewController, animated: Bool) {
        guard let vc = viewControllers.first(where: {$0.className == vc.className}) else {
            pushViewController(vc, animated: animated)
            return
        }
        popToViewController(vc, animated: animated)
    }
    func pushReplacement(_ vc: UIViewController, animated: Bool) {
        pushViewController(vc, animated: animated)
        guard let current = viewControllers.last else {
            return
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
            self.viewControllers.removeAll(where: {$0 == current})
        }
    }
}
